#include "DoOpDictionary.h"
#include "DevilSemantic.h"

void DoOpDictionary::ds_dict::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;

	state.getOpStack().push(CRefPtr< _DoObject >(new DoDictionary("")));
}

void DoOpDictionary::ds_left::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_right::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_length::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	
	DoDictionary* dict = toDict(obj1);
	state.getOpStack().push(newNumber((int)dict->size()));
}

bool DoOpDictionary::ds_length::match(DevilSemantic &state) const 
{
	if (state.getOpStack().size() < 1)
		return false;
	CRefPtr< _DoObject > obj1 = state.getOpStack().top(0);
	if (obj1->type() == eDictionary)
		return true;
	return false;
}

void DoOpDictionary::ds_maxlength::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_begin::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;

	state.getDictStack().push(obj1);
}

void DoOpDictionary::ds_end::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	
	state.getDictStack().pop();
}

void DoOpDictionary::ds_def::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
		
	state.getDictStack().put(obj2, obj1);
}

void DoOpDictionary::ds_load::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2 = state.getDictStack().lookup(obj1, state);
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	
	if (obj2.get() == NULL)
		CXXTHROW;
	state.getOpStack().push(obj2);
}

void DoOpDictionary::ds_store::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_get::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

bool DoOpDictionary::ds_get::match(DevilSemantic &state) const 
{
	if (state.getOpStack().size() < 2)
		return false;
	CRefPtr< _DoObject > obj1 = state.getOpStack().top(1);
	if (obj1->type() == eDictionary)
		return true;
	return false;
}

void DoOpDictionary::ds_put::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj3 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	
	toDict(obj3)->put(obj2, obj1);
}

bool DoOpDictionary::ds_put::match(DevilSemantic &state) const 
{
	if (state.getOpStack().size() < 3)
		return false;
	CRefPtr< _DoObject > obj1 = state.getOpStack().top(2);
	if (obj1->type() == eDictionary)
		return true;
	return false;
}

void DoOpDictionary::ds_undef::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_known::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_where::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;

	obj2 = state.getDictStack().findDict(obj1);
	if (obj2.get() == 0) {
		state.getOpStack().push(CRefPtr< _DoObject > (new DoBoolean(false)));
	} else {
		state.getOpStack().push(obj2);
		state.getOpStack().push(CRefPtr< _DoObject > (new DoBoolean(true)));
	}
}

void DoOpDictionary::ds_copy::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

bool DoOpDictionary::ds_copy::match(DevilSemantic &state) const 
{
	if (state.getOpStack().size() < 1)
		return false;
	CRefPtr< _DoObject > obj1 = state.getOpStack().top(0);
	if (obj1->type() == eDictionary)
		return true;
	return false;
}

void DoOpDictionary::ds_forall::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj2 = state.getOpStack().pop();
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	
	DoDictionary* dict = toDict(obj2);
	DoDictionary::CDictIter it = dict->begin();
	while(it != dict->end()) {
		state.getOpStack().push(it->first);
		state.getOpStack().push(it->second);
		
		obj1->execute(state);
		
		++it;
	}
}

bool DoOpDictionary::ds_forall::match(DevilSemantic &state) const 
{
	if (state.getOpStack().size() < 2)
		return false;
	CRefPtr< _DoObject > obj1 = state.getOpStack().top(1);
	if (obj1->type() == eDictionary)
		return true;
	return false;
}

void DoOpDictionary::ds_currentdict::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1 = state.getDictStack().top(0);
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;

	state.getOpStack().push(obj1);
}

void DoOpDictionary::ds_errordict::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_$error::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_systemdict::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_userdict::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	
	obj1 = state.getDictStack().userdict();
	state.getOpStack().push(obj1);
}

void DoOpDictionary::ds_globaldict::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	
	state.getOpStack().push(state.getDictStack().globaldict());
}

void DoOpDictionary::ds_statusdict::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_countdictstack::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_dictstack::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

void DoOpDictionary::ds_cleardictstack::execute(DevilSemantic &state)
{
	CRefPtr< _DoObject > obj1;
	CRefPtr< _DoObject > obj2;
	CRefPtr< _DoObject > obj3;
	CRefPtr< _DoObject > obj4;
	CRefPtr< _DoObject > obj5;
	CXXTHROW
}

